﻿using System;
using System.IO;

namespace AllInOne
{
    public class LogHelper
    {
        public static void WriteLog(string msg)
        {
            string fileName = DateTime.Now.ToString("yyyy-MM-dd") + "Log.txt";
            string logPath = AppDomain.CurrentDomain.BaseDirectory + @"log\";
            if (!Directory.Exists(logPath))
            {
                Directory.CreateDirectory(logPath);
            }
            if (!File.Exists(logPath + fileName))
            {
                FileStream fs = File.Create(logPath + fileName);
                fs.Close();
                fs.Dispose();
            }
            using (StreamWriter sw = File.AppendText(logPath + fileName))
            {
                sw.WriteLine("------------------------------------------------------");
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + msg);
            }
        }

        public static void WriteData(string msg)
        {
            string fileName = DateTime.Now.ToString("yyyy-MM-dd") + "Data.txt";
            string logPath = AppDomain.CurrentDomain.BaseDirectory + @"log\";
            if (!Directory.Exists(logPath))
            {
                Directory.CreateDirectory(logPath);
            }
            if (!File.Exists(logPath + fileName))
            {
                FileStream fs = File.Create(logPath + fileName);
                fs.Close();
                fs.Dispose();
            }
            using (StreamWriter sw = File.AppendText(logPath + fileName))
            {
                sw.WriteLine("------------------------------------------------------");
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + msg);
            }
        }
    }
}
